<script setup lang="ts">
import { ref, computed, onMounted, onBeforeUnmount, reactive } from 'vue';

const props: any = defineProps<{
    ujt: any;
    model: string;
    book: string;
    type?: string;
}>();
const { $global, $fn } = props.ujt;

const { cmBookData } = $fn.useBook(props);

const rtdata: any = reactive({
    tm: {
        timeout: null,
        starttime: 0,
        endtime: 0,
        wait: 300,
        immediate: false,
    },
});
// 响应式数据
const isMenuActive = ref(false);
const isSearchActive = ref(false);
const isMobile = ref(false);
const searchQuery = ref('');
const fontSize = ref(16);
const expandedVolumes = ref([]); // 展开卷

// 当前章节内容
const cmCurChapter: any = computed(() => {
    let tmpChapter: any = {};
    tmpChapter = cmAllChapters.value?.find(
        (chapter: any) => chapter.sn === $global.location.query?.id
    );
    if (!tmpChapter?.sn) {
        tmpChapter = cmBookData.value[0].cc[0].cc[0];
    }
    $fn.AsRouter.setTitle(tmpChapter?.li + ' - ' + cmBookData.value[0].ch);
    return tmpChapter;
});
// 搜索结果
const searchResults = ref([]);
// 计算属性：上一章、下一章
const cmAllChapters = computed(() => {
    return cmBookData.value[0].cc.flatMap((volume: any) => volume.cc);
});
const cmCurChapterIndex = computed(() => {
    return cmAllChapters.value.findIndex(
        (chapter: any) => chapter.sn === cmCurChapter.value?.sn
    );
});
const cmHasPrevChapter = computed(() => {
    return cmCurChapterIndex.value > 0;
});
const cmHasNextChapter = computed(() => {
    return cmCurChapterIndex.value < cmAllChapters.value.length - 1;
});

// 方法
const toggleMenu = () => {
    isMenuActive.value = !isMenuActive.value;
};

const toggleSearch = () => {
    isSearchActive.value = !isSearchActive.value;
    if (!isSearchActive.value) {
        searchQuery.value = '';
        searchResults.value = [];
    }
};

const closeSearch = () => {
    isSearchActive.value = false;
    searchQuery.value = '';
    searchResults.value = [];
};

const toggleVolume = (volumeId: string) => {
    const index = expandedVolumes.value.indexOf(volumeId);
    if (index > -1) {
        expandedVolumes.value.splice(index, 1);
    } else {
        expandedVolumes.value.push(volumeId);
    }
};

const selectChapter = (chapter: any) => {
    $fn.setquery({ id: chapter.sn });
    isMenuActive.value = false;
};

const prevChapter = () => {
    if (cmCurChapterIndex.value > 0) {
        $fn.setquery({
            id: cmAllChapters.value[cmCurChapterIndex.value - 1].sn,
        });
    }
};

const nextChapter = () => {
    if (cmCurChapterIndex.value < cmAllChapters.value.length - 1) {
        $fn.setquery({
            id: cmAllChapters.value[cmCurChapterIndex.value + 1].sn,
        });
    }
};

const increaseFontSize = () => {
    if (fontSize.value < 24) {
        fontSize.value += 1;
    }
};

const decreaseFontSize = () => {
    if (fontSize.value > 12) {
        fontSize.value -= 1;
    }
};

const handleSearch = () => {
    $fn.As.debounce(() => {
        const querystr: any = searchQuery.value.trim();
        if (!querystr) {
            searchResults.value = [];
            return;
        }
        searchResults.value = cmAllChapters.value
            ?.filter((chapter: any) => chapter.co.includes(querystr))
            .slice(0, 100)
            .map((el: any) => {
                const findArr: any = el.co.split(querystr);
                return {
                    sn: el.sn,
                    li: el.li,
                    preview: `...${findArr[0].slice(
                        -20
                    )}<b>${querystr}</b>${findArr[1].slice(0, 20)}...`,
                };
            });
    }, rtdata.tm)();
};

const goToSearchResult = (result: any) => {
    if (result?.sn) {
        $fn.setquery({
            id: result.sn,
        });
        isSearchActive.value = false;
        searchQuery.value = '';
        searchResults.value = [];
    }
};

const checkDevice = () => {
    isMobile.value = window.innerWidth <= 768;
};

// 生命周期钩子
onMounted(() => {
    checkDevice();
    window.addEventListener('resize', checkDevice);

    // 默认展开第一个卷宗
    if (cmBookData.value[0].cc.length > 0) {
        expandedVolumes.value.push(cmBookData.value[0].cc[0].sn);
    }
});

onBeforeUnmount(() => {
    window.removeEventListener('resize', checkDevice);
});
</script>

<template>
    <div class="novel-reader dark-theme">
        <!-- 顶部导航栏 -->
        <header class="reader-header">
            <div class="header-content">
                <button class="menu-toggle" @click="toggleMenu">
                    <span class="hamburger-icon"></span>
                </button>
                <h1 class="novel-title">{{ cmBookData[0].ch }}</h1>
                <button class="search-toggle" @click="toggleSearch">
                    <svg
                        xmlns="http://www.w3.org/2000/svg"
                        width="24"
                        height="24"
                        viewBox="0 0 24 24"
                        fill="none"
                        stroke="currentColor"
                        stroke-width="2"
                        stroke-linecap="round"
                        stroke-linejoin="round"
                    >
                        <circle cx="11" cy="11" r="8"></circle>
                        <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
                    </svg>
                </button>
            </div>
        </header>

        <!-- 搜索面板 -->
        <div class="search-panel" :class="{ active: isSearchActive }">
            <div class="search-container">
                <div class="search-input-wrapper">
                    <input
                        type="text"
                        v-model="searchQuery"
                        placeholder="搜索小说内容..."
                        class="search-input"
                        @input="handleSearch"
                    />
                    <button class="close-search" @click="closeSearch">×</button>
                </div>
                <div class="search-results" v-if="searchResults.length > 0">
                    <div
                        v-for="(result, index) in searchResults"
                        :key="index"
                        class="search-result-item"
                        @click="goToSearchResult(result)"
                    >
                        <div class="result-title">
                            {{ result.li }}
                        </div>
                        <div
                            class="result-preview"
                            v-html="result.preview"
                        ></div>
                    </div>
                </div>
                <div
                    class="no-results"
                    v-else-if="searchQuery && searchResults.length === 0"
                >
                    未找到相关内容
                </div>
            </div>
        </div>

        <div class="reader-container">
            <!-- 侧边栏菜单 -->
            <aside class="sidebar" :class="{ active: isMenuActive }">
                <div class="volume-list">
                    <h2 class="sidebar-title">{{ cmBookData[0].ch }}</h2>
                    <div
                        v-for="volume in cmBookData[0].cc"
                        :key="volume.sn"
                        class="volume-item"
                    >
                        <div
                            class="volume-header"
                            @click="toggleVolume(volume.sn)"
                        >
                            <h3 class="volume-title">{{ volume.cl }}</h3>
                            <span
                                class="toggle-icon"
                                :class="{
                                    expanded: expandedVolumes.includes(
                                        volume.sn
                                    ),
                                }"
                            >
                                ▼
                            </span>
                        </div>
                        <ul
                            class="chapter-list"
                            v-show="expandedVolumes.includes(volume.sn)"
                        >
                            <li
                                v-for="chapter in volume.cc"
                                :key="chapter.sn"
                                class="chapter-item"
                                :class="{
                                    active: cmCurChapter?.sn === chapter.sn,
                                }"
                                @click="selectChapter(chapter)"
                            >
                                {{ chapter.li }}
                            </li>
                        </ul>
                    </div>
                </div>
            </aside>

            <!-- 阅读内容区域 -->
            <main class="reader-content">
                <div class="content-container">
                    <div class="chapter-header">
                        <h2 class="chapter-title">
                            {{ cmCurChapter.li }}
                        </h2>
                        <div class="chapter-meta">
                            <template
                                v-for="attr in Object.keys(cmCurChapter)"
                                :key="attr"
                            >
                                <span
                                    v-if="
                                        cmCurChapter[attr] &&
                                        !['co', 'li', 'sn', 'ty'].includes(attr)
                                    "
                                >
                                    {{ cmCurChapter[attr] }}
                                </span>
                            </template>
                        </div>
                    </div>

                    <div
                        class="chapter-content"
                        :style="{ fontSize: fontSize + 'px' }"
                    >
                        <div
                            v-if="cmCurChapter.co && props.type === 'html'"
                            v-html="cmCurChapter.co"
                        ></div>
                        <template v-else>
                            {{ cmCurChapter.co }}
                        </template>
                    </div>

                    <div class="reader-controls">
                        <button
                            class="control-btn prev-next-btn"
                            @click="prevChapter"
                            :disabled="!cmHasPrevChapter"
                        >
                            上一篇
                        </button>
                        <div class="font-controls">
                            <button
                                class="font-btn"
                                @click="decreaseFontSize"
                                :disabled="fontSize <= 12"
                            >
                                A-
                            </button>
                            <span class="font-size-display"
                                >{{ fontSize }}px</span
                            >
                            <button
                                class="font-btn"
                                @click="increaseFontSize"
                                :disabled="fontSize >= 24"
                            >
                                A+
                            </button>
                        </div>
                        <button
                            class="control-btn prev-next-btn"
                            @click="nextChapter"
                            :disabled="!cmHasNextChapter"
                        >
                            下一篇
                        </button>
                    </div>
                </div>
            </main>
        </div>

        <!-- 移动端浮动按钮 -->
        <div class="mobile-fab" v-if="isMobile">
            <button class="fab-btn" @click="toggleMenu">
                <svg
                    xmlns="http://www.w3.org/2000/svg"
                    width="24"
                    height="24"
                    viewBox="0 0 24 24"
                    fill="none"
                    stroke="currentColor"
                    stroke-width="2"
                    stroke-linecap="round"
                    stroke-linejoin="round"
                >
                    <line x1="3" y1="12" x2="21" y2="12"></line>
                    <line x1="3" y1="6" x2="21" y2="6"></line>
                    <line x1="3" y1="18" x2="21" y2="18"></line>
                </svg>
            </button>
        </div>
    </div>
</template>

<style scoped lang="scss">
.novel-reader {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: #121212;
    font-family: 'Microsoft YaHei', sans-serif;
    color: #e0e0e0;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.reader-header {
    background: rgba(30, 30, 30, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 15px rgba(0, 0, 0, 0.5);
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid #333;
    transition: all 0.3s ease;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: none;
    position: relative;
    transition: all 0.3s ease;
}

.menu-toggle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(100, 100, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s, height 0.4s;
}

.menu-toggle:hover::after {
    width: 40px;
    height: 40px;
}

.menu-toggle:hover {
    transform: scale(1.1);
}

.hamburger-icon {
    display: block;
    width: 24px;
    height: 2px;
    background: #bb86fc;
    position: relative;
    transition: all 0.3s ease;
}

.hamburger-icon:before,
.hamburger-icon:after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background: #bb86fc;
    left: 0;
    transition: all 0.3s ease;
}

.hamburger-icon:before {
    top: -8px;
}

.hamburger-icon:after {
    bottom: -8px;
}

.novel-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #bb86fc;
    margin: 0;
    text-align: center;
    flex-grow: 1;
    padding: 0 20px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 0 8px rgba(187, 134, 252, 0.3);
    transition: all 0.3s ease;
}

.search-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: #bb86fc;
    transition: all 0.3s ease;
    position: relative;
    border-radius: 50%;
}

.search-toggle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(187, 134, 252, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s, height 0.4s;
}

.search-toggle:hover::after {
    width: 40px;
    height: 40px;
}

.search-toggle:hover {
    color: #e0e0e0;
    transform: scale(1.1);
}

.search-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: blur(4px);
}

.search-panel.active {
    opacity: 1;
    visibility: visible;
}

.search-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background: #1e1e1e;
    padding: 20px 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    max-height: 80vh;
    overflow-y: auto;
    transform: translateY(-20px);
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.search-panel.active .search-container {
    transform: translateY(0);
}

.search-input-wrapper {
    display: flex;
    padding: 0 20px 20px 20px;
}

.search-input {
    flex-grow: 1;
    padding: 0 16px;
    height: 58px;
    border: 1px solid #333;
    border-radius: 4px 0 0 4px;
    font-size: 16px;
    outline: none;
    background: #2d2d2d;
    color: #e0e0e0;
    transition: all 0.3s ease;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.search-input:focus {
    border-color: #bb86fc;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3),
        0 0 0 2px rgba(187, 134, 252, 0.2);
}

.close-search {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 58px;
    height: 60px;
    background: #2d2d2d;
    border: 1px solid #333;
    border-left: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    font-size: 24px;
    color: #bb86fc;
    transition: all 0.3s ease;
}

.close-search:hover {
    background: #bb86fc;
    color: #121212;
    transform: scale(1.05);
}

.search-results {
    max-height: 60vh;
    overflow-y: auto;
}

.search-result-item {
    padding: 16px 20px;
    border-bottom: 1px solid #333;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.search-result-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: rgba(187, 134, 252, 0.1);
    transition: width 0.4s ease;
    z-index: 0;
}

.search-result-item:hover::before {
    width: 100%;
}

.search-result-item:hover {
    background: rgba(187, 134, 252, 0.1);
    padding-left: 25px;
}

.result-title {
    font-weight: 600;
    margin-bottom: 6px;
    color: #e0e0e0;
    position: relative;
    z-index: 1;
}

.result-preview {
    color: #aaa;
    font-size: 14px;
    position: relative;
    z-index: 1;
}

.result-preview b {
    color: #bb86fc;
    font-weight: bold;
}

.no-results {
    text-align: center;
    padding: 50px 20px;
    color: #777;
    font-size: 18px;
}

.reader-container {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.sidebar {
    width: 300px;
    background: #1e1e1e;
    border-right: 1px solid #333;
    overflow-y: auto;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.3);
    position: relative;
}

.sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: linear-gradient(to bottom, #bb86fc, #03dac6);
}

.sidebar-title {
    padding: 25px 20px;
    margin: 0;
    font-size: 1.3rem;
    border-bottom: 1px solid #333;
    background: linear-gradient(90deg, #1e1e1e, #2d2d2d);
    color: #bb86fc;
    transition: all 0.3s ease;
    position: sticky;
    top: 0;
    z-index: 10;
    text-shadow: 0 0 8px rgba(187, 134, 252, 0.3);
}

.volume-item {
    border-bottom: 1px solid #333;
    transition: all 0.3s ease;
}

.volume-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    cursor: pointer;
    user-select: none;
    background: rgba(187, 134, 252, 0.05);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.volume-header::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: rgba(187, 134, 252, 0.1);
    transition: width 0.4s ease;
    z-index: 0;
}

.volume-header:hover::after {
    width: 100%;
}

.volume-header:hover {
    background: rgba(187, 134, 252, 0.1);
    padding-left: 25px;
}

.volume-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #e0e0e0;
    transition: color 0.3s ease;
    position: relative;
    z-index: 1;
}

.toggle-icon {
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), color 0.3s ease;
    color: #bb86fc;
    font-size: 14px;
    position: relative;
    z-index: 1;
}

.toggle-icon.expanded {
    transform: rotate(180deg);
    color: #03dac6;
}

.chapter-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.chapter-item {
    padding: 14px 20px 14px 45px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    color: #e0e0e0;
    position: relative;
    overflow: hidden;
}

.chapter-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: rgba(187, 134, 252, 0.05);
    transition: width 0.4s ease;
    z-index: 0;
}

.chapter-item:hover::before {
    width: 100%;
}

.chapter-item:hover {
    background: rgba(187, 134, 252, 0.05);
    color: #bb86fc;
    padding-left: 50px;
}

.chapter-item.active {
    background: rgba(187, 134, 252, 0.2);
    border-left: 3px solid #bb86fc;
    color: #bb86fc;
    font-weight: 500;
}

.chapter-item.active::before {
    background: rgba(187, 134, 252, 0.2);
}

.reader-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 25px;
    transition: background-color 0.3s ease;
    background: #121212;
}

.content-container {
    max-width: 800px;
    margin: 0 auto;
}

.chapter-header {
    margin-bottom: 35px;
    padding-bottom: 25px;
    border-bottom: 1px solid #333;
    transition: border-color 0.3s ease;
    text-align: center;
}

.chapter-title {
    font-size: 2rem;
    margin: 0 0 15px 0;
    color: #bb86fc;
    transition: color 0.3s ease;
    text-shadow: 0 0 8px rgba(187, 134, 252, 0.3);
}

.chapter-meta {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 25px;
    color: #03dac6;
    font-size: 1rem;
    transition: color 0.3s ease;
}

.chapter-content {
    line-height: 1.9;
    color: #e0e0e0;
    margin-bottom: 45px;
    text-wrap: break-word;
    word-break: break-all;
    white-space: pre-wrap;
    transition: color 0.3s ease;
    font-size: 1.1rem;
}

.reader-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 0;
    border-top: 1px solid #333;
    transition: border-color 0.3s ease;
}

.control-btn {
    padding: 14px 30px;
    height: 60px;
    background: linear-gradient(135deg, #bb86fc, #3700b3);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    min-width: 120px;
    text-align: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: linear-gradient(135deg, #3700b3, #bb86fc);
    transition: width 0.5s ease;
    z-index: -1;
}

.control-btn:hover:not(:disabled)::before {
    width: 100%;
}

.control-btn:hover:not(:disabled) {
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.4);
    transform: translateY(-3px);
}

.control-btn:disabled {
    background: #333;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.control-btn:disabled::before {
    display: none;
}

.prev-next-btn {
    padding: 14px 30px;
}

.font-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.font-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1px solid #333;
    background: #1e1e1e;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    color: #bb86fc;
    position: relative;
    overflow: hidden;
}

.font-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: #bb86fc;
    transition: width 0.4s ease;
    z-index: -1;
}

.font-btn:hover:not(:disabled)::before {
    width: 100%;
}

.font-btn:hover:not(:disabled) {
    color: #121212;
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.font-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.font-size-display {
    min-width: 70px;
    text-align: center;
    color: #e0e0e0;
    font-weight: 500;
    transition: color 0.3s ease;
    font-size: 1.1rem;
}

.mobile-fab {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 90;
}

.fab-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #bb86fc, #3700b3);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.fab-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 100%;
    background: linear-gradient(135deg, #3700b3, #bb86fc);
    transition: width 0.5s ease;
    z-index: -1;
}

.fab-btn:hover::before {
    width: 100%;
}

.fab-btn:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    transform: translateY(-5px) scale(1.05);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .menu-toggle {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 150;
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .reader-container {
        padding-top: 0;
    }

    .chapter-title {
        font-size: 1.7rem;
    }

    .reader-controls {
        flex-direction: column;
        gap: 20px;
    }

    .content-container {
        padding: 0 20px;
    }

    .control-btn {
        width: 100%;
        padding: 16px;
    }

    .prev-next-btn {
        padding: 16px;
    }

    .sidebar-title {
        font-size: 1.2rem;
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .header-content {
        padding: 12px 15px;
    }

    .novel-title {
        font-size: 1.1rem;
        padding: 0 10px;
    }

    .sidebar {
        width: 280px;
    }

    .volume-header,
    .chapter-item {
        padding: 15px;
    }

    .chapter-item {
        padding-left: 40px;
    }

    .font-btn {
        width: 42px;
        height: 42px;
    }

    .font-size-display {
        min-width: 60px;
    }

    .chapter-title {
        font-size: 1.5rem;
    }

    .control-btn {
        padding: 14px 20px;
        font-size: 1rem;
    }
}
</style>
